
import os
import re
index_full = os.path.join(os.getenv('APPDATA'),'DxfMerge','文件夹索引.txt')
open(index_full, "w", encoding='utf-8').close()
def append_line(line, file):
    with open(file, "a", encoding='utf-8') as fw:
        fw.write(line + '\n')
def prepare_test():
    main_dir = os.path.dirname(__file__)
    print(main_dir)
    di = 0
    for d in os.listdir(main_dir):
        d_full = os.path.join(main_dir, d)
        print(d_full)
        if os.path.isfile(d_full):
            continue
        di += 1
        d3 = str(di).zfill(3)
        print(f'【{d3}】、{d}')
        append_line(f'{d3}\t{d_full}', index_full)
        for f in os.listdir(d_full):
            filename, file_extension = os.path.splitext(f)
            print(f'【{d3}】 {filename}')

def extract_filenames(f):
    reg_folder_file = re.compile(r'【\d\d\d】 .+')
    with open(f, 'r') as f:
        for line in f.readlines():
            # if reg_folder_file.match('【574】 08层架2件'):
            if  reg_folder_file.search(line):
                print(line.strip())
if __name__ == '__main__':
    prepare_test()
    # extract_filenames(r"D:\dl\422.dxf")
 


